<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <div id="app">
        <v-a></v-a>
        <v-b></v-b>
    </div>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/pubsub-js/1.9.3/pubsub.min.js"></script>
<script src="../../js/vue.js"></script>
<script>
    Vue.config.productionTip=false;
    new Vue({
        el:"#app",
        components:{
            "v-a":{
                template:`<span @click="clickFn">v-a组件</span>`,
                data(){
                  return {
                      msg:"msg from v-a"
                  }
                },
                methods:{
                    clickFn(){
                        //发布
                        PubSub.publish('msg', this.msg);
                    }
                }
            },
            "v-b":{
                template:`<span>{{msg}}</span>`,
                data(){
                  return {
                      msg:"v-b组件"
                  }
                },
                mounted(){
                    //订阅
                    PubSub.subscribe('msg', (msg, data) => {
                        this.msg = data;
                    });
                }
            }
        }
    })

</script>
</html>